<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Vue App</title>
  <style>
    .box1 {
      padding: 20px;
      width: 300px;
      height: 300px;
      background-color: #bfa;
    }

    .box2 {
      width: 100px;
      height: 100px;
      background-color: purple;
    }
  </style>
</head>
<body>
  <div class="app">
    <!-- 事件修饰符 
        .prevent    阻止默认行为 
        .stop       阻止冒泡
        .once       绑定一次
        .capture    使用事件捕获模式
        .self       event.target 是当前元素时才触发
        .passive    默认行为立即执行, 无需等待事件回调执行完成
        - 修饰符可以连写, 依次生效
    -->
    <!-- 阻止默认行为, 停止冒泡 .prevent .stop -->
    <form @submit.prevent="sendRequest" @click="formClick" action="http://www.jd.com" method="get">
        username: <input type="text" name="admin" value="" placeholder="username"/> <br>
        password: <input type="password" name="admin" value="" placeholder="password"/> <br>
        <input type="submit" value="提交" @click.stop="submit">
    </form>
    <br>
    <!-- 阻止默认行为, 停止冒泡 -->
    <a href="http://www.baidu.com" @click.prevent="showInfo">跳转百度</a>
    <br>
    <!-- 事件只绑定一次 .once -->
    <button @click.once="showInfo">once click</button>

    <!-- 事件捕获模式 capture self -->
    <div class="box1" @click.capture="window.alert('box1')">
      <div class="box2" @click="window.alert('box2')"></div>
    </div>

    <!-- wheel scroll 滚轮和滚动条滚动两个事件-->
    <a href="http://www.baidu.com" @click.passive="window.alert('a.href')">a.href</a>
  </div>
</body>
<script src="../js/vue.js"></script>
<script type="text/javascript">
  Vue.config.productionTip = false
  const vm = new Vue({
    el: '.app',
    data: {
      msg: '消息!',
      window
    },
    methods: {
        formClick() {
            console.log('form click')
        },
        sendRequest(event) {
            console.log('提交表单数据, 不跳转')
        },
        submit(event) {
            console.log('submit-------')
        },
        showInfo(event) {
            // event.preventDefault();
            console.log('show Info: ', event.target)
        }
    }
  })


</script>
</html>